// Copyright Leonid Shlyapnikov 2010
// Distributed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html
//    author: Leonid Shlyapnikov, created on: Sep 16, 2010

#ifndef FIXPARSER_CPP_SRC_MAIN_FIXPARSER_FIELDWRITERVISITOR_H_
#define FIXPARSER_CPP_SRC_MAIN_FIXPARSER_FIELDWRITERVISITOR_H_

namespace fixparser {

template<typename OSTREAM>
class FieldWriterVisitor {
public:
    explicit FieldWriterVisitor(OSTREAM* output): output_(output), fieldDelimiter_(0x01) {
    }

    FieldWriterVisitor(OSTREAM* output, const int fieldDelimiter): output_(output), fieldDelimiter_(fieldDelimiter) {
    }

    virtual ~FieldWriterVisitor() {
    }

    void visit(const Field* field) {
        using fixparser::String;

        const String& tag = field->tag();
        const String& value = field->value();

        output_->write(tag.c_str(), tag.length());
        output_->put('=');
        output_->write(value.c_str(), value.length());
        output_->put(0x01);
    }

private:
    OSTREAM* output_;
    const char fieldDelimiter_;
};

}

#endif  // FIXPARSER_CPP_SRC_MAIN_FIXPARSER_FIELDWRITERVISITOR_H_
